<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${config.pack}.mappers.${beanName}Mapper">

	<!-- 1、配置返回结果Map和参数Map -->

${"\t"}<resultMap type="${beanName}" id="base${beanName}ResultMap">
${"\t"}${"\t"}<id property="${columnList[0].javaPropertyName}" column="${columnList[0].dbColumnName}"/>
		<#list columnList as column>
			<#if column_index!=0>
${"\t"}${"\t"}<result property="${column.javaPropertyName}" column="${column.dbColumnName}"/>		
			</#if>
		</#list>
${"\t"}</resultMap>

${"\t"}<resultMap type="${beanName}" id="${simpleBeanName}ResultMap" extends="base${beanName}ResultMap">
${"\t"}</resultMap>

${"\t"}<resultMap type="${beanShowVo}" id="${simpleBeanName}ShowVoResultMap" extends="base${beanName}ResultMap">
${"\t"}</resultMap>

${"\t"}<parameterMap type="${beanName}" id="${simpleBeanName}ParameterMap">
<#list columnList as column>
${"\t"}${"\t"}<parameter property="${column.javaPropertyName}" javaType="${column.mybatisJavaType}" jdbcType="${column.mybatisJdbcType}"<#if column.mybatisTypeHandler?exists><#if column.mybatisTypeHandler?length gt 0> typeHandler="${column.mybatisTypeHandler}"</#if></#if> />
</#list>
${"\t"}</parameterMap>


${"\t"}<!-- 2、各个SeqID -->

${"\t"}<insert id="add" parameterMap="${simpleBeanName}ParameterMap">
${"\t"}${"\t"}INSERT INTO ${config.tblName} (<#list columnList as column>${column.dbColumnName}<#if column_has_next>,</#if></#list>) VALUES (
<#list columnList as column>
${"\t"}${"\t"}${r"#{"}${column.javaPropertyName}, jdbcType=${column.mybatisJdbcType}${r"}"}<#if column_has_next>,</#if>
</#list>
${"\t"}${"\t"})
${"\t"}</insert>

${"\t"}<!-- 判断不可重复的属性是否已经存在，这里默认只判断deptName属性，具体的业务再进行修改添加 -->
	<!--
	
	-->

${"\t"}<select id="getById" resultMap="${simpleBeanName}ResultMap" parameterType="string">
${"\t"}${"\t"}SELECT * FROM ${config.tblName} WHERE ${columnList[0].dbColumnName} = ${r"#{"}value${r"}"}
${"\t"}</select>

${"\t"}<select id="page" resultMap="${simpleBeanName}ShowVoResultMap" parameterType="${beanQueryVo}">
${"\t"}${"\t"}SELECT * FROM ${config.tblName} 
${"\t"}${"\t"}<where>
			<#list columnList as column>
${"\t"}${"\t"}${"\t"}<if test="${column.javaPropertyName} != null and ${column.javaPropertyName} !='' ">
${"\t"}${"\t"}${"\t"}${"\t"}${"\t"}AND	${column.dbColumnName} = ${r"#{"}${column.javaPropertyName}, jdbcType=${column.mybatisJdbcType}${r"}"} 
${"\t"}${"\t"}${"\t"}</if>			
			</#list>
${"\t"}${"\t"}</where>		
${"\t"}</select>

${"\t"}<select id="getTotal" resultType="long" parameterType="${beanQueryVo}">
${"\t"}${"\t"}SELECT COUNT(1) FROM ${config.tblName}
${"\t"}${"\t"}<where>
<#list columnList as column>
${"\t"}${"\t"}${"\t"}<if test="${column.javaPropertyName} != null and ${column.javaPropertyName} !='' ">
${"\t"}${"\t"}${"\t"}${"\t"}AND	${column.dbColumnName} = ${r"#{"}${column.javaPropertyName}, jdbcType=${column.mybatisJdbcType}${r"}"}
${"\t"}${"\t"}${"\t"}</if>			
</#list>
${"\t"}${"\t"}</where>
${"\t"}</select>

${"\t"}<delete id="deleteById" parameterType="string">
${"\t"}${"\t"}DELETE FROM ${config.tblName} WHERE ${columnList[0].dbColumnName} = ${r"#{"}value${r"}"}
${"\t"}</delete>

${"\t"}<update id="edit" parameterType="${beanName}">
${"\t"}${"\t"}UPDATE ${config.tblName} 
${"\t"}${"\t"}<set>
			<#list columnList as column>
			<#if column_index!=0>
${"\t"}${"\t"}${"\t"}<if test="${column.javaPropertyName} != null and ${column.javaPropertyName} !='' ">
${"\t"}${"\t"}${"\t"}${"\t"}${column.dbColumnName} = ${r"#{"}${column.javaPropertyName}, jdbcType=${column.mybatisJdbcType}${r"}"}, 
${"\t"}${"\t"}${"\t"}</if>			
			</#if>
			</#list>
${"\t"}${"\t"}</set>
${"\t"}${"\t"}WHERE ${columnList[0].dbColumnName} = ${r"#{"}${columnList[0].javaPropertyName}${r"}"} 
${"\t"}</update>

</mapper>
